package kr.hkit.androidcomplete02.ch11;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;

public class RadioCheck extends Activity {
	TextView mSample;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_radiocheck);

		mSample = (TextView) findViewById(R.id.ch11_txtsimple);

		RadioGroup ColGroup = (RadioGroup) findViewById(R.id.ch11_colorgroup);
		ColGroup.setOnCheckedChangeListener(mRadioCheck);

		CheckBox chkWhite = (CheckBox) findViewById(R.id.ch11_chkwhiteback);
		chkWhite.setOnCheckedChangeListener(mCheckChange);

		ToggleButton tgLang = (ToggleButton) findViewById(R.id.ch11_tglanguage);
		tgLang.setOnCheckedChangeListener(mCheckChange);

	}

	RadioGroup.OnCheckedChangeListener mRadioCheck = new RadioGroup.OnCheckedChangeListener() {
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			if (group.getId() == R.id.ch11_colorgroup) {
				switch (checkedId) {
				case R.id.ch11_rared:
					mSample.setTextColor(Color.RED);
					break;
				case R.id.ch11_ragreen:
					mSample.setTextColor(Color.GREEN);
					break;
				case R.id.ch11_rablue:
					mSample.setTextColor(Color.BLUE);
					break;
				}
			}
		}
	};

	OnCheckedChangeListener mCheckChange = new CompoundButton.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			// TODO Auto-generated method stub
			if (buttonView.getId() == R.id.ch11_chkwhiteback) {
				if (isChecked) {
					mSample.setBackgroundColor(Color.WHITE);
				} else {
					mSample.setBackgroundColor(Color.TRANSPARENT);
				}
			}
			if (buttonView.getId() == R.id.ch11_tglanguage) {
				if (isChecked) {
					mSample.setText("샘플");
				} else {
					mSample.setText("Sample");
				}
			}
		}

	};
}
